﻿504.七进制数
char* convertToBase7(int num) {
    if (num == 0)
    {
        return "0";
    }
    char* ans = (char*)malloc(sizeof(char) * 10000001);
    int count = 0, flag = 0;
    if (num < 0)
    {
        flag = 1;
        num = -num;
    }

    while (num)
    {
        sprintf(ans + (count++), "%d", num % 7);
        num /= 7;
    }

    if (flag == 1)
    {
        sprintf(ans + count, "%c", '-');
    }

    int l = 0, r = strlen(ans) - 1;
    while (l < r)
    {
        char temp = ans[l];
        ans[l] = ans[r];
        ans[r] = temp;
        l++;
        r--;
    }
    return ans;
}

507.完美数
bool checkPerfectNumber(int num) {
    if (num == 1)
    {
        return false;
    }
    int sum = 1;
    for (int i = 2; i * i <= num; i++)
    {
        if (num % i == 0)
        {
            sum += i;
            if (i != (num / i))
            {
                sum += (num / i);
            }
        }
    }
    if (sum == num)
    {
        return true;
    }
    else
    {
        return false;
    }
}